<?php

namespace Cck\ArticlesSystem\Http\Models;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\Pivot;

/**
 * @property integer $tag_id
 * @property integer $taggable_id
 * @property string $taggable_type
 * 
 * @property-read Tag $tag
 * @property-read Model $taggable
 */
class Taggable extends Pivot
{
    protected $table = 'taggables';

    public $timestamps = false;

    public $incrementing = true;

    protected $fillable = [
        'tag_id', 'taggable_type', 'taggable_id'
    ];

    protected $casts = [
        'tag_id' => 'integer',
        'taggable_id' => 'integer'
    ];

    public function tag()
    {
        return $this->belongsTo(Tag::class, 'tag_id', 'id');
    }

    public function taggable()
    {
        return $this->morphTo('taggable', 'taggable_type', 'taggable_id');
    }
}
